package nina.yiyou.attendance.s10merge.compute.wage

import nina.yiyou.attendance.s10merge.input.AttendLeaveExcelReader

class WageHourCalculator {

  WageHourCalculator(double hourTotal, List<AttendLeaveExcelReader.Line> leaveList) {
    _hourTotal = hourTotal
    _leaveList = leaveList
  }

  double calc() {
    double result = _hourTotal - _leaveList.stream()
        .filter { UNPAID.contains(it.leaveType()) }
        .mapToDouble { it.leaveDuration() }
        .sum()

    return Math.max(result, 0)
  }

  private static final Set<String> UNPAID = [
      '事假',
      '其他',
  ]

  private final double _hourTotal
  private final List<AttendLeaveExcelReader.Line> _leaveList
}
